//
//  MYMySetRevampPasswordVC.m
//  MuYing
//
//  Created by tbb on 2019/8/8.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "MYMySetRevampPasswordVC.h"

@interface MYMySetRevampPasswordVC ()

@end

@implementation MYMySetRevampPasswordVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isNavShadow = YES;
    self.navigationItem.title = kYQLS(@"修改密码");
    self.rightItemTitle = kYQLS(@"保存");
}

-(void)setupView {
    [super setupView];
    self.listTableView.backgroundColor = HexColor(0xFAFAFA);
    kYQREGISTERTABLEVIEWCELL([MYMySetRevampPasswordCell class])
}

-(void)rightItemAction:(UIButton *)sender {
    MYMySetRevampPasswordCell *cell = [self.listTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    if (cell.textField.text.length < 6) {
        [MBProgressHUD showMessage:kYQLS(@"请输入至少6位密码")];
        return;
    }
    [self updateUserPasswordApi:cell.textField.text];
}
#pragma mark - 设置用户密码
- (void)updateUserPasswordApi:(NSString *)pass
{
    NSMutableDictionary *dic = NSMutableDictionary.new;

    dic[@"userId"] = [YQPUserTool account].userId;
    dic[@"password"] = pass;

    [YQPNetWorkingManager sendPostRequest:kPOST_SAVE_PASSWORD_URL parameters:dic success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        [MBProgressHUD showSuccess:responseObject.msg];
        [self.navigationController popToRootViewControllerAnimated:YES];

        
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        
    }];
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    MYMySetRevampPasswordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MYMySetRevampPasswordCell"];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 58;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.001;
}

@end
